package vn.pdg.zoombie.ui;

import java.io.File;

import vn.pdg.zoombie.bean.Utils;
import vn.pdg.zoombie.ui.zoomimager.ImageViewTouch;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class AdjustPhoto extends Activity implements OnClickListener{

	public static final String EXTRA_URL_PHOTO = "EXTRA_URL_PHOTO";
	public static final String EXTRA_ORIENT_PHOTO = "EXTRA_ORIENT_PHOTO";
	private ImageViewTouch imageAdjust;
	private Button btCancle, btOk;
	private String urlPhoto;
	private String orientPhoto;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.adjust_photo);
		loadControl();
		loadData();
		
	}
	
	private void loadControl(){
		btCancle 	= (Button) findViewById(R.id.bt_cancle);
		btOk		= (Button) findViewById(R.id.bt_ok);
		imageAdjust = (ImageViewTouch) findViewById(R.id.image_adjust);
		btCancle.setOnClickListener(this);
		btOk.setOnClickListener(this);
	}
	
	private void loadData(){
		Intent data 	= getIntent();
		urlPhoto 		= data.getStringExtra(EXTRA_URL_PHOTO);
		orientPhoto 	= data.getStringExtra(EXTRA_ORIENT_PHOTO);
		int degrees = 0;
		if(orientPhoto !=null)
			degrees = Integer.parseInt(orientPhoto);
		
		Bitmap b = Utils.decodeFile(new File(urlPhoto), 320);
		b 		= Utils.rotate(b, degrees);
		
		imageAdjust.setImageBitmapReset(b, 0, true);
		
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.bt_ok:
			
			break;
		case R.id.bt_cancle:
			finish();
			break;
		default:
			break;
		}
	}
}
